package zy010;

import java.io.File;
import java.util.HashMap;

import javax.activation.MimetypesFileTypeMap;

public class zy2 {
	public static void main(String[] args) {
		File src = new File("d:\\");
		
		HashMap<String, Integer> map= new HashMap<>();
		HashMap<String, Integer> count=countFile(src,map);
		count.forEach((key,value)->System.out.println(key+":"+value));
	}

	private static HashMap<String, Integer>countFile(File src, HashMap<String, Integer> map) {
		File[] listFiles = src.listFiles();
		if(listFiles!=null){
			for(File file:listFiles){
				if(file.isFile()){
//					String name=file.getName();
					String type=new MimetypesFileTypeMap().getContentType(file);
					map.put(type, map.getOrDefault(type, 0)+1);
				}else{
					countFile(file,map);
				}
			}
		}
		return map;
	}
	
}
